package controller

import (
	"context"
	api "{{package_info.api}}"
	service "{{package_info.service}}"
	consts "{{package_info.consts}}"
)



var {{table_info.firstUpperName}} = {{table_info.camelName}}Controller{}

type {{table_info.camelName}}Controller struct {
	BaseController
}

func (c *{{table_info.camelName}}Controller) Add(ctx context.Context, req *api.{{table_info.firstUpperName}}AddReq) (res *api.{{table_info.firstUpperName}}AddRes, err error) {
	res = new(api.{{table_info.firstUpperName}}AddRes)
	err = service.{{table_info.firstUpperName}}().Add(ctx, req)
	return
}

func (c *{{table_info.camelName}}Controller) List(ctx context.Context, req *api.{{table_info.firstUpperName}}ListReq) (res *api.{{table_info.firstUpperName}}ListRes, err error) {
	res = new(api.{{table_info.firstUpperName}}ListRes)
	if req.PageSize == 0 {
		req.PageSize = consts.PageSize
	}
	if req.PageNum == 0 {
		req.PageNum = 1
	}
	total, {{table_info.camelName}}s, err := service.{{table_info.firstUpperName}}().List(ctx, req)
	res.Total = total
	res.CurrentPage = req.PageNum
	res.{{table_info.firstUpperName}}List = {{table_info.camelName}}s
	return
}

func (c *{{table_info.camelName}}Controller) Get(ctx context.Context, req *api.{{table_info.firstUpperName}}DetailReq) (res *api.{{table_info.firstUpperName}}DetailRes, err error) {
	res = new(api.{{table_info.firstUpperName}}DetailRes)
	service.{{table_info.firstUpperName}}().GetById(ctx, req.Id)
	return
}


func (c *{{table_info.camelName}}Controller) Edit(ctx context.Context, req *api.{{table_info.firstUpperName}}EditReq) (res *api.{{table_info.firstUpperName}}EditRes, err error) {
	err = service.{{table_info.firstUpperName}}().Edit(ctx, req)
	return
}

func (c *{{table_info.camelName}}Controller) Delete(ctx context.Context, req *api.{{table_info.firstUpperName}}DelReq) (res *api.{{table_info.firstUpperName}}DelRes, err error) {
	err = service.{{table_info.firstUpperName}}().Delete(ctx, req.Id)
	return
}

func (c *{{table_info.camelName}}Controller) BatchDelete(ctx context.Context, req *api.{{table_info.firstUpperName}}BatchDelReq) (res *api.{{table_info.firstUpperName}}BatchDelRes, err error) {
	err = service.{{table_info.firstUpperName}}().BatchDelete(ctx, req.Ids)
	return
}